//
//  ChargeTVC.m
//  LoveFreshBeen
//
//  Created by vinsent on 16/10/20.
//  Copyright © 2016年 魏根. All rights reserved.
//

#import "ChargeTVC.h"
#import "ChargeCell.h"
#import "MyCouponModel.h"

static NSString *reuseID = @"ChargeTVC";

@interface ChargeTVC ()

@property(nonatomic,strong)NSArray *dataArray;

@end

@implementation ChargeTVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ChargeCell" bundle:nil] forCellReuseIdentifier:reuseID];
    
    [self getDataArray];
    
    self.tableView.allowsSelection = NO;
    
}

- (void)setDataArray:(NSArray *)dataArray{
    
    _dataArray = dataArray;
    
    [self.tableView reloadData];
}
//获取网络数据 , 加入 数组
- (void)getDataArray{
    
    if (!_dataArray) {
        
        [[NetWorkingTool shareInstance]getDatawithParam:@"9" WithUrlString:@"MyCoupon.json.php" withSuccessBlock:^(NSDictionary *data) {
            
            NSArray *array = data[@"data"];
            
            NSMutableArray *nmArray = [NSMutableArray array];
            
            for (int i = 0; i < array.count; i++) {
                
                MyCouponModel *model = [[MyCouponModel alloc]init];
                
                [model yy_modelSetWithDictionary:array[i]];
                
//                [model setValue:(array[i])[@"Description"] forKey:@"myDescription"];
                
                [nmArray addObject:model];
            }
            self.dataArray = nmArray.copy;
            
        } withFailedBlock:^(NSError *error) {
            
            NSLog(@"%@",error);
        } withErrorBlock:^(NSString *message) {
            
            NSLog(@"%@",message);
        }];
    }
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ChargeCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID forIndexPath:indexPath];
    
    cell.model = self.dataArray[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 150;
}

@end
